package logic

import (
	"context"
	"order/model/mysql"

	"order/internal/svc"
	"order/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderGoodCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderGoodCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderGoodCreateLogic {
	return &OrderGoodCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderGoodCreateLogic) OrderGoodCreate(in *order.OrderGoodCreateRequest) (*order.OrderGoodCreateResponse, error) {
	// todo: add your logic here and delete this line
	good := mysql.OrderGood{
		UserId:     int(in.UserId),
		OrderId:    int(in.OrderId),
		GoodTitle:  in.GoodTitle,
		GoodPrice:  in.GoodPrice,
		GoodStock:  in.GoodStock,
		GoodCover:  in.GoodCover,
		GoodStatus: in.GoodStatus,
	}
	err := good.OrderGoodCreate()
	if err != nil {
		return nil, err
		logx.Error(err)
	}
	return &order.OrderGoodCreateResponse{Id: int64(good.ID)}, nil
}
